package frame.networks.tables;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import model.components.networks.network.VirtualNetwork;
import model.components.networks.network.PhysicalNetwork;

import frame.MopraFrame;

@SuppressWarnings("serial")
public class NetworksTableTabbedPane extends JTabbedPane implements MouseListener
{
	private MopraFrame mopraFrame;
	public MopraFrame getFrame(){ return mopraFrame; }
	public void setFrame( MopraFrame mopraFrame ){ this.mopraFrame = mopraFrame; }
	
	private PhysicalNetworksTable physicalNetworksTable;
	public PhysicalNetworksTable getPhysicalNetworksTable(){ return physicalNetworksTable; }
	public void setPhysicalNetworksTable( PhysicalNetworksTable physicalNetworksTable ){ this.physicalNetworksTable = physicalNetworksTable; }
	
	private VirtualNetworksTable virtualNetworksTable;
	public VirtualNetworksTable getVirtualNetworksTable(){ return virtualNetworksTable; }
	public void setVirtualNetworksTable( VirtualNetworksTable virtualNetworksTable ){ this.virtualNetworksTable = virtualNetworksTable; }
	
	public NetworksTableTabbedPane( List< PhysicalNetwork > physicalNetworks, List< VirtualNetwork > virtualNetworks, MopraFrame mopraFrame )
	{
		this.setFrame( mopraFrame );
		
		this.setPhysicalNetworksTable( new PhysicalNetworksTable( physicalNetworks, this.getFrame() ) );
		this.setVirtualNetworksTable( new VirtualNetworksTable( virtualNetworks, this.getFrame() ) );
		
		this.setTabPlacement( SwingConstants.TOP );
		this.setPreferredSize( new Dimension( 200, 10 ) );
		this.addTab( "Physical", null, new JScrollPane( this.getPhysicalNetworksTable() ), null );
		this.addTab( "Virtual",   null, new JScrollPane( this.getVirtualNetworksTable() ), null );
		
		this.addMouseListener( this );
	}
	
	@Override
	public void mouseClicked( MouseEvent mouseEvent )
	{
		JSplitPane splitPane = this.getFrame().getNetworksPanel().getSplitPane();
		
		if( this.getSelectedIndex() == 0 )
			splitPane.setRightComponent( this.getFrame().getNetworksPanel().getPhysicalNetworksVisualizationViewersTabbedPane() );
		
		else if( this.getSelectedIndex() == 1 )
			splitPane.setRightComponent( this.getFrame().getNetworksPanel().getVirtualNetworksVisualizationViewersTabbedPane() );
	}
	@Override
	public void mouseEntered( MouseEvent mouseEvent ){}
	@Override
	public void mouseExited( MouseEvent mouseEvent ){}
	@Override
	public void mousePressed( MouseEvent mouseEvent ){}
	@Override
	public void mouseReleased( MouseEvent mouseEvent ){}
	
}
